package com.lagou.edu.controller;

import com.lagou.edu.dao.InfoDao;
import com.lagou.edu.datasource.ZkDataSourceFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class IndexController {
    @Autowired
    private InfoDao infoDao;

    @ResponseBody
    @GetMapping("/")
    public String index(HttpServletResponse response) throws IOException {
        String now = infoDao.getNow();
        return String.format("<h1>%s</h1>", now);
    }


    @ResponseBody
    @GetMapping("/c")
    public String gen(String p) {
        ZkDataSourceFactory.config(null, null, p);
        return "Done";
    }
}
